<template>
  <div>

    <Panel title="充电枪管理" useBack>
         <ModifyForm
        slot="body"
        :editColumn="editColumn"
        :temporaryData='temporaryData'
        labelWidth="150px"
        :updateData="updateData"
      >
        <p
          slot="title"
        ></p>

      </ModifyForm>
    </Panel>
  </div>
</template>
<script>
import Panel from "@/components/Panel";
import ModifyForm from "@/components/ModifyForm";
import ModalPanel from "@/components/ModalPanel";
import FileUpload from '@/components/FileUpload';
import request from "@/tools/request";
export default {
  name:'gunInfo_',
  components: {
    FileUpload,
    Panel,
    ModalPanel,
    ModifyForm
  },
  data() {
    return {
     configValue:"",
      editorOption: {},
      typeList: [],
      temporaryData: {
        coverImg: [],
        publishStatus: false
      },
      editColumn: [
        {
          name: "充电枪名称",
          prop: "name",
          type: "text",
          width:12,
          required: true
        },
        {
          name: "充电枪编号",
          prop: "sn",
          type: "text",
          width:12,
          required: true
        },
        {
          name: "所属电桩",
          prop: "pileId",
          type: "select",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id': '','name': "请选择状态"}],
          onChange: () => {},
          width:12,
          required: true
        },
        {
          name: "设备编号",
          width: 12,
          prop: "deviceSn",
          type: "text",
          required: true
        },
       
        // {
        //   name: "在线状态",
        //   prop: "online",
        //   type: "select",
        //   optionBindLabel: 'name',
        //   optionBindValue: 'id',
        //   optionList: [{'id': '','name': "请选择状态"},{'id': 1,'name': "在线"},{'id':0, 'name':"停用"},{'id':2, 'name':"异常"}],
        //   width:12,
        //   required: true
        // },
       
        {
          name: "车位编号",
          width: 12,
          prop: "parkNo",
          type: "text",
          required: true
        },
        {
          name: "额定电流(A)",
          width: 12,
          prop: "current",
          type: "number",
          required: true
        },
        {
          name: "额定功率(kw)",
          width: 12,
          prop: "power",
          type: "number",
          required: true
        },
        {
          name: "额定电压下限(V)",
          width: 12,
          prop: "voltageLower",
          type: "number",
          required: true
        },
        {
          name: "额定电压上限(V)",
          width: 12,
          prop: "voltageUpper",
          type: "number",
          required: true
        },
        {
          name: "备注",
          width: 12,
          prop: "mark",
          type: "text",
          required: false
        },
      ],
    };
  },
  computed: {
 

  },
  methods: {
   async updateData(values) {
     
     const {sn, pileId, id, name, floorLockState, parkNo, mark, online, power, current, voltageLower, voltageUpper, deviceSn} = values
    //  return
     let url = id ? "/iot/pile/gun/update":"/iot/pile/gun/add"
     let msg = id ? "编辑成功" : "添加成功"
     let res =await request({
       url: url,
       method:"POST",
       data:{sn, pileId, id, name, floorLockState, parkNo, mark, online, power, current, voltageLower, voltageUpper, deviceSn}
     })
     if ( res.code !== 0) return
      this.$message.success(msg)
      this.$router.go(-1)
    },
    async fetchData(id){
      let { template } = await request({
        url: "/iot/pile/gun/info/"+id,
        method: "GET",
        data: {}
      });
      this.temporaryData = template
    },
    //充电桩
    async getIotPile(){
       let { list } =await request({
       url: '/iot/pile/all',
       method:"POST",
       data:{}
     })
     this.editColumn[2].optionList = list
    }
  },
  created() {
    if(this.$route.query.id)
      this.fetchData(this.$route.query.id)
      this.getIotPile()
  }
};
</script>

<style lang='scss' module>

</style>